﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

/* Copyright (c) 2014
 * author: Ricky Kratochwil
 * @ date: 2014-05-16
 * @ summary: Used to handle the individual bricks on the grid
*/

namespace Engine
{
	class CBrick
	{
		private int		m_iBrickAlign;
		private int		m_iBrickType;
		private Bitmap	m_oImage;
		private bool	m_bDamaged;

		public CBrick()
		{
			m_iBrickType    = Const.BLOCK_ICE;			//Default brick type is ice!
			m_iBrickAlign	= Const.BRICK_ALIGN_SINGLE;	//Ice has no alignment, thus use single
		}

		public CBrick(int iBrickType, int iBrickAlign)
		{
			m_iBrickType	= iBrickType;
			m_iBrickAlign	= iBrickAlign;

			if(m_iBrickType == Const.BLOCK_ROCK && !m_bDamaged)
			{
				switch(m_iBrickAlign)
				{
					case Const.BRICK_ALIGN_SINGLE :
						m_oImage = new Bitmap(Properties.Resources.brick_stone, new Size(Const.GRID_DIM, Const.GRID_DIM));
						break;
					case Const.BRICK_ALIGN_CONT :
						m_oImage = new Bitmap(Properties.Resources.brick_stone_small_cont, new Size(Const.GRID_DIM, Const.GRID_DIM));
						break;
					case Const.BRICK_ALIGN_LEFT :
						m_oImage = new Bitmap(Properties.Resources.brick_stone_small_cont_left, new Size(Const.GRID_DIM, Const.GRID_DIM));
						break;
					case Const.BRICK_ALIGN_RIGHT :
						m_oImage = new Bitmap(Properties.Resources.brick_stone_small_cont_right, new Size(Const.GRID_DIM, Const.GRID_DIM));
						break;
				}
			}
			else if(m_iBrickType == Const.BLOCK_SPIKES)
			{
				m_oImage = new Bitmap(Properties.Resources.spikes, new Size(Const.GRID_DIM, Const.GRID_DIM));
			}
		}


		/* Serves as an destructor
		 *  @ requires:	
		 *      -/-
		 *  @ modifies:	
		 *      -/-
		 *  @ ensures:	
		 *     - Image is set before deletion
		 *  @ remarks:	
		 *     -/-
		 *  @ author / date:
		 *     - KR / 2014.05.19
		   */
		public void Destroy()
		{
			if(m_oImage != null)
				m_oImage.Dispose();
		}

		/* Check if player can stand on brick
		 *  @ requires:	
		 *      -/-
		 *  @ modifies:	
		 *      -/-
		 *  @ ensures:	
		 *     -/-
		 *  @ remarks:	
		 *     -/-
		 *  @ author / date:
		 *     - KR / 2014.05.18
		   */
		public bool GetSolid()
		{
			if(m_iBrickType == Const.BLOCK_ICE)
				return false;
			else
				return true;
		}

//////////////////////////////////////////////////////////////////////////////////////////////////////
////////// DAMAGE

		//Make brick damaged
		//@ KR / 2014.07.09
		public void SetDamaged()
		{
			m_bDamaged = true;

			switch(m_iBrickAlign)
			{
				case Const.BRICK_ALIGN_SINGLE :
					m_oImage = new Bitmap(Properties.Resources.brick_stone_broken, new Size(Const.GRID_DIM, Const.GRID_DIM));
					break;
				case Const.BRICK_ALIGN_CONT :
					m_oImage = new Bitmap(Properties.Resources.brick_stone_broken_small_cont, new Size(Const.GRID_DIM, Const.GRID_DIM));
					break;
				case Const.BRICK_ALIGN_LEFT :
					m_oImage = new Bitmap(Properties.Resources.brick_stone_broken_small_cont_left, new Size(Const.GRID_DIM, Const.GRID_DIM));
					break;
				case Const.BRICK_ALIGN_RIGHT :
					m_oImage = new Bitmap(Properties.Resources.brick_stone_broken_small_cont_right, new Size(Const.GRID_DIM, Const.GRID_DIM));
					break;
			}
		}

		//Return true if brick is damaged
		//@ KR / 2014.07.09
		public bool GetBrickDamaged()
		{
			return m_bDamaged;
		}

		/* Get brick type
		 *  @ requires:	
		 *      -/-
		 *  @ modifies:	
		 *      -/-
		 *  @ ensures:	
		 *     -/-
		 *  @ remarks:	
		 *     -/-
		 *  @ author / date:
		 *     - KR / 2014.05.19
		   */
		public int GetBrickType()
		{
			return m_iBrickType;
		}


		//Get brick alignment
		//@ KR / 2014.05.20
		public int GetBrickAlign()
		{
			return m_iBrickAlign;
		}


		/* Return brick bitmap for drawing ops
		 *  @ requires:	
		 *      -/-
		 *  @ modifies:	
		 *      -/-
		 *  @ ensures:	
		 *     -/-
		 *  @ remarks:	
		 *     -/-
		 *  @ author / date:
		 *     - KR / 2014.05.19
		   */
		public Bitmap GetBrickBitmap()
		{
			return m_oImage;
		}
	}
}